package com.qst.survey.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qst.survey.entity.UserReply;
import com.qst.survey.mapper.UserReplyMapper;
import com.qst.survey.service.UserReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Date: 2021/3/21 14:20
 * @Description: 用户回答问题具体服务类
 */
@Service
public class UserReplyServiceImpl implements UserReplyService {
    @Autowired
    UserReplyMapper userReplyMapper;

    /**
     * @param userReply ：用户回复实体类
     * @description TODO   增加用户回复的信息,存入数据库中
     * @date 2021/4/2
     */
    @Override
    public void addReply(UserReply userReply) {
        userReplyMapper.insert(userReply);
    }

    @Override
    public Integer countReplay() {
        Integer integer = userReplyMapper.selectCount(null);
        return integer;
    }
    /**
     * @param id ：
     * @description TODO   通过问卷你的来判断是否用户已经回答该问卷了
     * @date 2021/4/2
     */
    @Override
    public boolean judgeReplay(Integer id,Integer userId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("question_id",id);
        queryWrapper.eq("user_id",userId);
        UserReply userReply = userReplyMapper.selectOne(queryWrapper);
        return userReply!=null;
    }


}
